﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SCRUM.Core.DAO;
using SCRUM.Core.BusinessObjects;
using SCRUM.Core.MembershipProviders;
using System.Web.UI.DataVisualization.Charting;

/// <summary>
/// Represents selection for types of charts that are available fot the application
/// </summary>
public partial class ChartSelection : System.Web.UI.UserControl
{
    /// <summary>
    /// Event triggered when selection of chart changes
    /// </summary>
    public event EventHandler SelectedChartChangedEvent;

    /// <summary>
    /// Gets the selected chart.
    /// </summary>
    /// <value>The selected chart.</value>
    public string SelectedChart
    {
        get
        {
            if (String.IsNullOrEmpty(this.DropDownListChart.SelectedValue))
            {
                return null;
            }
            else
            {
                return this.DropDownListChart.SelectedValue;
            }
        }
    }

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadCharts();
        }
    }

    /// <summary>
    /// Loads the charts.
    /// </summary>
    protected void LoadCharts()
    {
        DropDownListChart.DataSource = DAOBurndownchart.GetChartTypes();
        //DropDownListChart.DataTextField = "Name";
        //DropDownListChart.DataValueField = "Id";
        DropDownListChart.DataBind();
        DropDownListChart.Items.Insert(0, new ListItem((string)GetLocalResourceObject("ChooseChart"), String.Empty));
    }
       

    /// <summary>
    /// Selected index changed -> sends event
    /// </summary>
    /// <param name="sender">The sender.</param>
    /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
    protected void SelectedChartChanged(object sender, EventArgs e)
    {
        if (this.SelectedChartChangedEvent != null)
        {
            this.SelectedChartChangedEvent(sender, e);
        }
    }
}
